<?php
	include("config.php");
	header("Content-type: text/html; charset=utf-8"); 
	
	function md516($string){
		return substr(md5($string),8,16); 
	}	

	//获取研究生系统的所有老师
	if( $_POST['get_menu'] ){ 

		$test_snoopy = new Snoopy;

		$test_snoopy->agent = $agent;
		$test_snoopy->host = IP;

		$all_teacher_root_page = "http://202.206.245.111/ZNPK/Private/List_JS.aspx?xnxq=20140&js=";
		//$all_teacher_root_page2 = "http://".IP."/ZNPK/TeacherKBFB_rpt.aspx";
		
		//$test_snoopy->submit($all_teacher_root_page,$submit_var);
		$test_snoopy->fetch($all_teacher_root_page);
		$test_snoopy_results = $test_snoopy->results;
		$test_snoopy_results = iconv('GB2312','UTF-8//IGNORE',$test_snoopy_results);

		var_dump($test_snoopy_results);
		//停止截取位置
		$end_pos = strpos($test_snoopy_results,'<!DOCTYPE HTML PUBLIC');
		var_dump($end_pos);
		//开始截取位置
		$target_str = substr($test_snoopy_results,107,$end_pos-107);
		var_dump($target_str);

		$target_arr = explode('</option>',$target_str);
		var_dump($target_arr);
		//连接数据库
		$temp_conn = mysql_connect('localhost','root','');
		mysql_select_db('test',$temp_conn);
		mysql_query("set names 'utf8'");

		foreach( $target_arr as $key => $val){ 
			$value_s = strpos($val,'=');
			//var_dump($value_s);
			$value_e = strpos($val,'>');
			//var_dump($value_e);
			$cut_length = $value_e - $value_s;
			$target_value = substr($val,++$value_s,--$cut_length);	//真实的value值
			$id_s = strpos($val,'[');
			$id_e = strpos($val,']');
			$cut_length_id = $id_e - $id_s;
			//var_dump($cut_length_id);
			$target_id = substr($val,++$id_s,--$cut_length_id);	//真实的教师号
			//var_dump('target_id:'.$target_id);
			$name_s = strpos($val,']');
			$target_name = substr($val,++$name_s);
			var_dump($target_name);
			mysql_query("INSERT INTO test_teacher_qg (teacher_id,name,value) VALUES ('".$target_id."','".$target_name."','".$target_value."')");
			
		}
		/*
		//$test_arr = strpos($test_snoopy_results,'<option');
		$test_arr = substr_count($test_snoopy_results,'<option');	//查找option出现的次数
		$test_arr2 = substr_count($test_snoopy_results, '</option>');	//查找</option结束次数

		var_dump($test_arr);
		var_dump($test_arr2);
		$all_teacher_arr = array();
		$end_tag = 0;
		$start_tag = 0;
		for( $i=0 ; $i<$test_arr ; $i++ ){ 

			$temp_pos_start = strpos($test_snoopy_results,'<option',$start_tag);
			$end_tag = $temp_pos_start+7; 

			$temp_pos_end = strpos($test_snoopy_results,'</option>',$end_tag);
			$start_tag = $temp_pos_end+8;
			
			echo $temp_pos_start;
			echo '<br />';

		}
		
		$end_pos = strpos($test_snoopy_results,'<!DOCTYPE HTML PUBLIC');
		var_dump($end_pos);
		$target_str = substr($test_snoopy_results,90,$end_pos-90);
		var_dump($target_str);


		$page_html = new simple_html_dom();
		$page_html->load($test_snoopy_results);
		$opts = $page_html->find('option');		//option元素存在js的字符变量中
		//var_dump($opts);
		//$test_snoopy_results = mb_convert_encoding($test_snoopy->results, 'utf-8', 'gbk');
		//var_dump($test_snoopy_results);
		*/
	}

	//获取研究生系统的所有老师课表
	if( $_POST['get_table'] ){

		$test_snoopy = new Snoopy;
		$test_snoopy->agent = $agent;
		$test_snoopy->host = IP;

		$all_teacher_root_page = "http://202.206.245.111/ZNPK/TeacherKBFB_rpt.aspx";

		$submit_var = array();
		$submit_var['Sel_JS'] = '';
		$submit_var['Sel_XNXQ'] = '20140';
		$submit_var['type'] = '1';
		//连接数据库
		$all_teacher_array = array();
		$temp_conn = mysql_connect('localhost','root','');
		mysql_select_db('test',$temp_conn);
		mysql_query("set names 'utf8'");
		$all_teacher = mysql_query("SELECT * FROM test_teacher_qg");
		while( $row = mysql_fetch_array($all_teacher) ){ 
			$all_teacher_array[] = array(
				'id' => $row['id'],
				'teacher_id' => $row['teacher_id'],
				'name' => $row['name'],
				'value' => $row['value'],
				);
		}
		//var_dump($all_teacher_array);
		//$test_man = $all_teacher_array[0];
		//var_dump($test_man);
		/*
		$submit_var['Sel_JS'] = '0001060';
		$test_snoopy->submit($all_teacher_root_page,$submit_var);
		$test_result1 = iconv('GB2312','UTF-8//IGNORE',$test_snoopy->results);
		var_dump($test_result1);
		*/

		foreach( $all_teacher_array as $key => $val ){
		//foreach( $test_arr3 as $key => $val ){
			$id_in_table = $val['id'];
			$teacher_id = $val['teacher_id']; 

			$submit_var['Sel_JS'] = $val['value'];
			//$submit_var['Sel_JS'] = '0000374';

			$test_snoopy->submit($all_teacher_root_page,$submit_var);
			
			$temp_result = iconv('GB2312','UTF-8',$test_snoopy->results);
			var_dump($val['name']);
			$target_s = strpos($temp_result,'<table id="pageRpt" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>');
			$target_str = substr($temp_result,$target_s);
			//var_dump($target_s);
			$target_str = str_replace('\'', 'dota', $target_str);
			//var_dump($target_str);
			//var_dump($temp_result);
			mysql_query("INSERT INTO test_table_qg (teacher_id,teacher_num,table_text) VALUES ('".$id_in_table."','".$teacher_id."','".$target_str."')");
			
			sleep(2);
		}
	}

	//获取正方所有的教师
	if($_POST['get_ysu']){

		$ysu_snoopy = new Snoopy;
		$ysu_snoopy->agent = $agent;
		$ysu_snoopy->host = IP;
		$ysu_teacher_root_page = "http://jwc.ysu.edu.cn/zjdxgc/mycjcx/jskbcx.asp";
		$ysu_snoopy->fetch($ysu_teacher_root_page);
		$ysu_snoopy_result = $ysu_snoopy->results;
		var_dump($ysu_snoopy_result);

		$ysu_snoopy_result = iconv('GB2312','UTF-8//IGNORE',$ysu_snoopy_result);

		var_dump($ysu_snoopy_result);
		//$ysu_page_html = new simple_html_dom();
		//$ysu_page_html->load($ysu_snoopy_result);
		//$opts = $ysu_page_html->find("option");
		//var_dump($opts[0]);

		//计算开始截取位置
		$tar_str_pos_s = strpos($ysu_snoopy_result,'<select name="jsid" id="jsid">');
		var_dump($tar_str_pos_s);
		//计算结束截取位置
		$tar_str_pos_e = strpos($ysu_snoopy_result,'<input name="jsxm" type="text" class="input1" id="jsxm" value="" size="20" maxlength="20">');
		var_dump($tar_str_pos_e);
		//开始截取
		$target_str = substr($ysu_snoopy_result,$tar_str_pos_s,$tar_str_pos_e-$tar_str_pos_s);
		var_dump($target_str);
		//分割成数组
		$all_opt_arr = explode('</option>',$target_str);
		var_dump($all_opt_arr);
		$all_opt_arr_length = count($all_opt_arr);
		//去掉头和尾再循环处理
		$temp_for_length = $all_opt_arr_length-2;

		$temp_link = mysql_connect('localhost','root','');
		if( !$temp_link ){ 
			var_dump('no');
		}
		mysql_select_db('test',$temp_link);

		mysql_query("set names 'utf8'"); 

		for( $i=1 ; $i<=$temp_for_length ; $i++ ){
			$temp_str = $all_opt_arr[$i];
			//var_dump($temp_str); 
			$temp_start = strpos($temp_str,'=');
			//var_dump($temp_start);
			$temp_end = strpos($temp_str,'>');
			//var_dump($temp_end);
			$temp_sep = $temp_end-$temp_start;	//截取长度
			$temp_sep--;
			//var_dump($temp_sep);
			$temp_start++;
			$temp_end++;
			$target_str = substr($temp_str,$temp_start,$temp_sep);
			$target_name = substr($temp_str,$temp_end);
			var_dump($target_str);
			var_dump($target_name);
			
			mysql_query("INSERT INTO test_teacher (teacher_id, name) VALUES ('".$target_str."', '".$target_name."')");
		}

		mysql_close($temp_link);
		$opt_s_count = substr_count($ysu_snoopy_result,'<option');
		$opt_e_count = substr_count($ysu_snoopy_result,'</option>');
		var_dump($opt_s_count.'hahah'.$opt_e_count);

	}

	//获取教务系统的教师课表
	//form目标地址：
	//http://jwc.ysu.edu.cn/zjdxgc/mycjcx/jskbcx.asp    method:POST    name:form1
	//form需发送数据：
	//jsid
	//jsxm
	//show2   value(1)   hidden
	//dqxn    value(2014-2015)  hidden
	//dqxq		value(1)		hidden
	//yxid		value()			hidden
	//djz		value(12)		hidden
	//xqj		value(3)		hidden
	if( $_POST['get_all_table'] ){
		//Submit
		$send_var = array(
			'jsid' => '',
			'jsxm' => '',
			'show2' => '1',
			'dqxn' => '2014-2015',
			'dqxq' => '1',
			'yxid' => '',
			'djz' => '12',
			'xqj' => '3',
			);
		
		$temp_conn = mysql_connect('localhost','root','');
		mysql_select_db('test',$temp_conn);
		mysql_query("set names 'utf8'");
		$result_arr = mysql_query("SELECT * FROM test_teacher");
		//var_dump(mysql_fetch_array($result_arr,MYSQL_NUM));
		$result_array = array();
		while( $row = mysql_fetch_array($result_arr) ){ 
			$result_array[] = array(
				'id'=>$row['teacher_id'],
				'name'=>$row['name'],
				);
		}
		
		foreach( $result_array as $key => $val ){ 
			$table_snoopy = new Snoopy;
			
			$temp_var = $send_var;
			$temp_var['jsid'] = $val['id'];
			
			$table_snoopy->agent = $agent;
			$table_snoopy->host = IP;
			$temp_root_page = "http://jwc.ysu.edu.cn/zjdxgc/mycjcx/jskbcx.asp";
			$table_snoopy->submit($temp_root_page,$temp_var);
			$temp_result = $table_snoopy->results;
			$temp_result = iconv('GB2312','UTF-8//IGNORE',$temp_result);
			//var_dump($temp_result);
		
			$test_pos = strpos($temp_result,'<div align="center">星期日</div>');
			//var_dump($test_pos);
			$target_info = substr($temp_result,$test_pos);
			var_dump($target_info);
			mysql_query("INSERT INTO test_table (teacher_id, table_text) VALUES ('".$val['id']."', '".$target_info."')");
			sleep(2);
		}
	}

	if( $_POST['on_the_way'] ){

		$on_snoopy = new Snoopy;
		$on_snoopy->agent = $agent;
		$on_snoopy->host = IP;
		$target_page = "http://www.117go.com/tour/51462671";
		$on_snoopy->fetch($target_page);
		$on_page_result=  $on_snoopy->results;
		var_dump($on_page_result);
	}


	//分析课表并插入数据库
	if( $_REQUEST['table_in_db'] ){ 

		$temp_link = mysql_connect('localhost','root','');
		mysql_select_db('test',$temp_link);
		mysql_query("set names 'utf8'");
		
	}

	if( $_REQUEST['analysis'] ){ 

	} 

	//分析两个表中缺的课表
	if( $_REQUEST['teacher_table_diff'] ){ 
		$temp_link = mysql_connect('localhost','root','');
		mysql_select_db('test');
		mysql_query("set names 'utf8'");

		$all_teacher_query = mysql_query("SELECT * FROM test_teacher_qg");
		$all_teacher_arr = array();
		while( $row = mysql_fetch_array($all_teacher_query) ){ 
			$all_teacher_arr[] = array(
				'id'=> $row['id'],
				'teacher_id'=>$row['teacher_id'],
				'name'=>$row['name'],
				'value'=>$row['value'],
				);
		}

		$all_table_query = mysql_query("SELECT id,teacher_id,teacher_num FROM test_table_qg");
		$all_table_arr = array();
		while( $row = mysql_fetch_array($all_table_query) ){ 
			$all_table_arr[$row['teacher_id']] = array(
				
				'teacher_id'=>$row['teacher_id'],
				'teacher_num'=>$row['teacher_num'],
				);
		}
		foreach( $all_teacher_arr as $key => $val ){ 
			if( !$all_table_arr[$val['id']] ){ 
				var_dump($val);
			}

		}
	}

	if( $_REQUEST['aes_en'] ){ 
		$str = '我是明文我是明文我是明文我是明文我是明文dsfdghgasdfasdddddddd';  
	    $key = 'aSGJLGYEWERWRREW4567i8o';  
	      
	    $str1=AES::encode($key, $str);  
	    $str2=AES::decode($key, $str1);  
	      
	      
	    //echo '<xmp>';  
	    var_dump($str);  
	    var_dump($str1);  
	    var_dump($str2);  
	    var_dump(rtrim($str2));  
	}

	if( $_REQUEST['zf_test'] ){ 
		$on_snoopy = new Snoopy;
		$on_snoopy->agent = $agent;
		$on_snoopy->host = '202.206.245.231';
		$target_page = "http://202.206.245.231";
		$on_snoopy->fetch($target_page);
		$on_page_result=  iconv('','UTF-8//IGNORE',$on_snoopy->results);
		var_dump($on_page_result);
	}
	//转存老师信息
	if( $_REQUEST['store_teacher'] ){ 

		$now_time = date('Y-m-d H:i:s',time());
		$test_link = mysql_connect('localhost','root','');
		mysql_select_db("test");
		mysql_query("set names 'utf8'");
		$qg_teacher_query = mysql_query("SELECT * FROM test_teacher");
		$all_teacher_qg_arr = array();
		while( $row = mysql_fetch_array($qg_teacher_query) ){ 
			$all_teacher_qg_arr[] = array(
				'username' => $row['name'],
				'teacher_id' => $row['teacher_id'],
				);
		}
		//header();
		mysql_close($test_link);
		//var_dump($all_teacher_qg_arr);
		$test_link2 = mysql_connect('localhost','root','');
		mysql_select_db("ptime");
		mysql_query("set names 'utf8'");
		foreach( $all_teacher_qg_arr as $key => $val ){ 
			$exist_query = mysql_query("SELECT * FROM user WHERE studentid = '".$val['teacher_id']."'");
			if( ! mysql_fetch_array($exist_query) ){ 
				mysql_query("INSERT INTO user ( studentid , username ) VALUES ( '".$val['teacher_id']."','".$val['username']."' )");
				var_dump(array('1'));
			}
		}
		mysql_close($test_link2); 
	}

	//分析qg系统课表
	if( $_REQUEST['analysis_table'] ){ 

		$test_link = mysql_connect('localhost','root','');
		mysql_select_db("test");
		mysql_query("set names 'utf8'");
		$all_table_qg = mysql_query("SELECT * FROM test_table_qg");
		$all_table_arr = array();
		while( $row = mysql_fetch_array($all_table_qg) ){ 
			$all_table_arr[] = array(
				'teacher_num' => $row['teacher_num'],
				'table' => $row['table_text'],
				);
		}
		//var_dump($all_table_arr);exit;
		//更换数据库
		mysql_select_db("ptime");
		mysql_query("set names 'utf8'");
		
		$whole_table_arr = array();

		foreach( $all_table_arr as $key => $val ){ 
			$temp_table_text = $val['table'];
			$temp_table_text_td = explode('</td>', $temp_table_text);
			//等于2的是  无课表信息
			if( count($temp_table_text_td) != 2 ){ 
				//先提取部门信息
				//var_dump($temp_table_text_td);
				$part_info_td = $temp_table_text_td[2];
				//var_dump($part_info_td);
				$part_info_td_bm_pos = strpos($part_info_td,"部门：");
				$part_info_td_js_pos = strpos($part_info_td,"教师：");
				$part_info_td_bm_pos = $part_info_td_bm_pos+9;
				//获取工号
				$part_info_td_num_l = strpos($part_info_td, "[");
				$part_info_td_num_r = strpos($part_info_td, "]");
				$part_info_td_num = substr($part_info_td, ++$part_info_td_num_l, $part_info_td_num_r-$part_info_td_num_l);
				//var_dump($part_info_td_name);
				//获取性别
				$part_info_td_sex_pos = strpos($part_info_td, "性别：");
				$part_info_td_sex_pos = $part_info_td_sex_pos+9;
				$part_info_td_sex = substr($part_info_td,$part_info_td_sex_pos,3);
				
				$part_info_td_bm = substr($part_info_td, $part_info_td_bm_pos,$part_info_td_js_pos-$part_info_td_bm_pos);
				$part_info_td_bm = str_replace("&nbsp;", "", $part_info_td_bm);
				//var_dump(array($part_info_td_bm_pos,$part_info_td_js_pos,$part_info_td_bm));
				if( $part_info_td_sex == '女' ){ 
					$part_info_td_sex = '0';
				}else{ 
					$part_info_td_sex = '1';
				}
				//mysql_query("UPDATE user SET school_part = '".$part_info_td_bm."',sex = '".$part_info_td_sex."' WHERE studentid = '".$part_info_td_num."'");
				//$first_class = $second_class = $third_class = $forth_class = $night_class = 0;
				foreach( $temp_table_text_td as $key2 => $val2 ){ 
					$first_class = strpos($val2,'>一');
					$second_class = strpos($val2,'>二');
					$third_class = strpos($val2,'>三');
					$forth_class = strpos($val2,'>四');
					$night_class = strpos($val2,'>晚上');
					if( $first_class ){
						$first_index = $key2;
					}
					if( $second_class ){ 
						$second_index = $key2;
					}
					if( $third_class ){ 
						$third_index = $key2;
					}
					if( $forth_class ){ 
						$forth_index = $key2;
					}
					if( $night_class ){ 
						$night_index = $key2;
					}

				}
				unset($whole_table_arr);
				$whole_table_arr[] = array(
					'start' => $first_index,
					'end' => $second_index,
					);
				$whole_table_arr[] = array(
					'start' => $second_index,
					'end' => $third_index,
					);
				$whole_table_arr[] = array(
					'start' => $third_index,
					'end' => $forth_index,
					);
				$whole_table_arr[] = array(
					'start' => $forth_index,
					'end' => $night_index,
					);
				$whole_table_arr[] = array(
					'start' => $night_index,
					'end' => 45,
					);
				//var_dump($whole_table_arr);exit;

				//分析大课
				foreach( $whole_table_arr as $key3 => $val3 ){
					if( $key2 == 4 ){ 
						//var_dump($val2);
					}
					$week_n_counter = 1;	//星期几计数器
					$loop_start = $val3['start'];
					$loop_start++;
					$loop_end = $val3['end'];
					for( $i = $loop_start; $i < $loop_end; $i++ ){ 
						//var_dump($temp_table_text_td[$i]);
						$temp_string = $temp_table_text_td[$i];
						if( strpos($temp_string,'dota><br') || strpos($temp_string,'下<br>午') ){ 
							//无课
						}else{ 
							//有课
							$temp_class_pos_s = strpos($temp_string,'dota>');
							$temp_class_pos_e = strpos($temp_string,'<br>');
							$temp_string_tar = substr($temp_string,$temp_class_pos_s+5,$temp_class_pos_e-$temp_class_pos_s-5);
							//var_dump($temp_string_tar);
							$temp_string_tar_arr = explode(" ", $temp_string_tar);
							//var_dump($temp_string_tar_arr);
							//课程名
							$subject_name = $temp_string_tar_arr[0];
							//时间
							$subject_time_all = $temp_string_tar_arr[1];
							//地点
							$subject_place = $temp_string_tar_arr[2];
							//其他信息
							$subject_others = $temp_string_tar_arr[3];
							//截取开始结束周数
							$temp_start_w_s = strpos($subject_time_all,'[');
							$temp_start_w_e = strpos($subject_time_all,'周]');
							$temp_start_whole = substr($subject_time_all,++$temp_start_w_s,$temp_start_w_e-$temp_start_w_s);
							$temp_start_whole_arr = explode('-',$temp_start_whole);
							//var_dump($temp_start_whole_arr);
							$temp_start_week = $temp_start_whole_arr[0];
							$temp_end_week = $temp_start_whole_arr[1];
							//截取上课的节数, 直接根据$first_class得出
							$start_class = $key3*2+1;
							$end_class = $key3*2+2;
							$class_n = $start_class.",".$end_class;
							$store_arr = array(
								'subject_name' => $subject_name,
								'teacher_id' => $val['teacher_num'],
								'school_id' => '2',
								'room_id' => $subject_place,
								'week_n' => $week_n_counter,
								'week_start' => $temp_start_week,
								'week_end' => $temp_end_week,
								'class_n' => $class_n,
								'year' => '2014-2015',
								'term' => '1',
								);
							$target_id = md516(implode('-',$store_arr));
							//var_dump($target_id);
						
							mysql_query("INSERT INTO c_record ( id, subject_name, teacher_id, school_id, room_id, week_n, week_start, week_end, class_n, year, term, others)
										VALUES ('".$target_id."','".$subject_name."','".$val['teacher_num']."','2','".$subject_place."','".$week_n_counter."','".$temp_start_week."','".$temp_end_week."','".$class_n."','2014-2015','1','".$subject_others."')
										");
							
						}
						$week_n_counter++; 
					}
				}

			}
			var_dump($key);
		}

	}

	//分析本科教师课表
	if( $_REQUEST['analysis_table_ysu'] ){ 
		
		$temp_link = mysql_connect('localhost','root','');
		mysql_select_db("test");
		mysql_query("set names 'utf8'");
		$ysu_table_all_query = mysql_query("SELECT * FROM test_table");
		$ysu_table_all_arr = array();
		while( $row = mysql_fetch_array($ysu_table_all_query) ){ 
			$ysu_table_all_arr[] = array(
				'teacher_id' => $row['teacher_id'],
				'table_text' => $row['table_text'],
				);

		}
		//echo count($ysu_table_all_arr);exit;
		//var_dump($ysu_table_all_arr);
		$start_end_arr = array();

		foreach( $ysu_table_all_arr as $key => $val ){
			unset($start_end_arr);
			$ysu_table_arr_div = explode('<div align="center">',$val['table_text']);
			//var_dump($ysu_table_arr_div);
			//1-2节：2  ||  3-4节：10   ||   5-6节：18   ||   7-8节：28   ||   9-10节：36
			$start_end_arr[] = array(
				'start' => 2,
				'end' => 10,
				);
			$start_end_arr[] = array(
				'start' => 10,
				'end' => 18,
				);
			$start_end_arr[] = array(
				'start' => 18,
				'end' => 28,
				);	//在22和23上多出两个无效格
			$start_end_arr[] = array(
				'start' => 28,
				'end' => 36,
				);
			$start_end_arr[] = array(
				'start' => 36,
				'end' => 43,
				);
			//var_dump($start_end_arr);exit;

			mysql_select_db("ptime");
			mysql_query("set names 'utf8'");

			
			foreach( $start_end_arr as $key2 => $val2 ){

				$subject_class_s = $key2*2+1;
				$subject_class_e = $key2*2+2; 
				$week_n_counter = 1;
				
				$loop_start = $val2['start'];
				$loop_start++;
				$loop_end = $val2['end'];
				for( $i=$loop_start ; $i<$loop_end ; $i++ ){

				//var_dump($i); 
					$temp_table_div = $ysu_table_arr_div[$i];
					$temp_end_pos = strpos($temp_table_div,"<br><br>");
					//没课
					if( !$temp_end_pos ){ 

					}else{
					//有课
						//$hanzi_check = preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$temp_table_div);
						//删除所有的空格
						$temp_table_div = trim($temp_table_div);
						//var_dump($temp_table_div);
						//按<br>分割
						$temp_table_div_arr = explode('<br>', $temp_table_div);
						//var_dump($temp_table_div_arr);
						foreach( $temp_table_div_arr as $key3 => $val3 ){ 
							if( !strlen( $val3 ) ){ 
								$temp_empty_pos = $key3;
								//var_dump($temp_empty_pos);
							} 
						}
						$subject_name = $temp_table_div_arr[0];
						$subject_week_arr = explode('-',$temp_table_div_arr[1]);
						$subject_week_s = $subject_week_arr[0];		//开始周
						$subject_week_e = $subject_week_arr[1];		//结束周
						
						$class_n = "$subject_class_s,$subject_class_e";
						var_dump($class_n);
						$subject_week_e = str_replace("周", "", $subject_week_e);
						$subject_teacher = $temp_table_div_arr[2];	//上课老师
						$subject_place = $temp_table_div_arr[3];	//上课地点

						if( $temp_empty_pos == 4 ){ 
							$subject_others = "";
						}
						if( $temp_empty_pos == 5 ){ 
							$subject_others = $temp_table_div_arr[4];//其他信息
						}

						$store_arr = array(
							'subject_name' => $subject_name,
							'teacher_id' => $val['teacher_id'],
							'school_id' => 1,
							'room_id' => $subject_place,
							'week_n' => $week_n_counter,
							'week_start' => $subject_week_s,
							'week_end' => $subject_week_e,
							'class_n' => $class_n,
							'year' => '2014-2015',
							'term' => '1',
							);
						$target_id = md516(implode('-',$store_arr));
						//var_dump($target_id);
						//var_dump($temp_table_div);
						
						mysql_query("INSERT INTO c_record ( id, subject_name, teacher_id, school_id, room_id, week_n, week_start, week_end, class_n, year, term, others)
										VALUES ('".$target_id."','".$subject_name."','".$val['teacher_id']."','3','".$subject_place."','".$week_n_counter."','".$subject_week_s."','".$subject_week_e."','".$class_n."','2014-2015','1','".$subject_others."')
										");
						
						$insert_counter++;
					}

					if( $i != 22 && $i != 23 ){ 
						$week_n_counter++;
					}
				}
			}
			var_dump($key); 
		}
	}

?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
	<h3>获取信息</h3>
	<form action="get_teacher_table.php" method="POST">
		<input type="submit" name="get_menu" value="获取所有教师"></input>
		<input type="submit" name="get_table" value="获取所有课表qg"></input>
		<input type="submit" name="get_ysu" value="获取教务处所有老师"></input>
		<input type="submit" name="get_all_table" value="获取所有课表"></input>
		<input type="submit" name="on_the_way" value="在路上"></input>
	</form>
</body>
</html>